package com.yuyou.fn.controller;


import com.alibaba.fastjson.JSONObject;
import com.github.wens.mybatisplus.plugins.Page;
import com.github.wens.mybatisplus.toolkit.IdWorker;
import com.google.common.collect.Collections2;
import com.yuyou.fn.activity.entity.ActivityCampusSession;
import com.yuyou.fn.activity.entity.ActivityRegSituation;
import com.yuyou.fn.activity.service.IActivityCampusService;
import com.yuyou.fn.activity.service.IActivityCampusSessionService;
import com.yuyou.fn.activity.service.IActivityRegSituationService;
import com.yuyou.fn.activity.service.IActivityService;
import com.yuyou.fn.activity.vo.*;
import com.yuyou.fn.common.exception.BusException;
import com.yuyou.fn.common.service.ISmsService;
import com.yuyou.fn.common.util.*;
import com.yuyou.fn.educational.entity.*;
import com.yuyou.fn.educational.service.*;
import com.yuyou.fn.educational.vo.*;
import com.yuyou.fn.platform.entity.CustomerUser;
import com.yuyou.fn.platform.service.IAccessTokenService;
import com.yuyou.fn.platform.service.ICaptchaService;
import com.yuyou.fn.platform.service.IOauthService;
import com.yuyou.fn.platform.vo.AccessTokenVo;
import com.yuyou.fn.portal.entity.*;
import com.yuyou.fn.portal.service.*;
import com.yuyou.fn.portal.vo.*;
import com.yuyou.fn.settlement.entity.AccountRecharge;
import com.yuyou.fn.settlement.entity.MainAccount;
import com.yuyou.fn.settlement.service.IAccountRechargeService;
import com.yuyou.fn.settlement.service.IMainAccountService;
import com.yuyou.fn.vo.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ExecutionException;


/**
 * Created by wens on 16/10/24.
 */

@Controller
@RequestMapping(value="/api/m/activity")
public class MActivityController {

   @Resource
   private IActivityRegSituationService activityRegSituationService;

   @Resource
   private IActivityService activityService;

   @Resource
   private IBaseGradeService baseGradeService;

   @Resource
   private IActivityCampusService activityCampusService;

    @ApiOperation("获取年级")
    @RequestMapping(value = "/gradeList" ,method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<BaseGrade>> gradeList( HttpServletRequest request){
        List<BaseGrade> baseGradeList=baseGradeService.findAllOrderGrade();
        return ReturnResult.success(baseGradeList);
    }

    @ApiOperation("单个活动详情")
    @RequestMapping(value = "/findOneActivityDetail" ,method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<ActivityDetailVo> findOneActivityDetail(@RequestParam("activityId")long activityId, HttpServletRequest request){
        ActivityDetailVo activityQueryVo=activityService.findActivityDetailById(activityId);
        return ReturnResult.success(activityQueryVo);
    }


    @ApiOperation("报名活动")
    @RequestMapping(value = "/saveActivityRegSituation", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<ActivityRegSituation> saveActivityRegSituation(@Valid @RequestBody ActivityRegSaveVo activityRegSaveVo, HttpServletRequest request ) {
        ActivityRegSituation activityRegSituation = activityRegSituationService.saveActivityRegSituation(activityRegSaveVo);
        return  ReturnResult.success(activityRegSituation);
    }

    @ApiOperation("已报名活动场次列表")
    @RequestMapping(value = "/findActivityRegSession", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<ActivityRegListVo> findActivityRegSession(@RequestParam("activityId")long activityId,
                                                                     @RequestParam("studentName")String studentName,
                                                                     @RequestParam("studentPhoneNo")String studentPhoneNo,
                                                                     HttpServletRequest request ) {
        ActivityRegListVo activityRegListVo=activityRegSituationService.findActivityRegSessionListByNamePhone(activityId,studentName,studentPhoneNo);
        return  ReturnResult.success(activityRegListVo);
    }

    @ApiOperation("活动签到")
    @RequestMapping(value = "/signActivityRegSituation",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> signActivityRegSituation(@Valid @ModelAttribute ActivitySignVo activitySignVo, HttpServletRequest request ) {
        activityRegSituationService.signActivityRegSituation(activitySignVo);
        return  ReturnResult.success("OK");
    }

    @ApiOperation("活动校区和场次信息")
    @RequestMapping(value = "/activityCampusSessionList",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult< List<ActivityCampusDetailVo>> activityCampusSessionList(@RequestParam("activityId")long activityId, HttpServletRequest request ) {
        List<ActivityCampusDetailVo> campusDetailVos = activityCampusService.findCanRegActivityCampusByActivityId(activityId);
        return  ReturnResult.success(campusDetailVos);
    }

}
